package com.qf.shoppingorder.controller;

/**
 * FanoutExchangeController
 *
 * @author lx
 * @date 2024-03-20 10:04
 */

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FanoutExchangeController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/fanout")
    public String send() {
        rabbitTemplate.convertAndSend("fanout-exchange","","hello");
        return "ok";
    }

    @RabbitListener(queues = {"fanout.queue1"})
    public void recv(Message message) {
        System.out.println("fanout.queue1===");
        System.out.println(message);
    }

    @RabbitListener(queues = {"fanout.queue2"})
    public void recv2(Message message) {
        System.out.println("fanout.queue2===");
        System.out.println(message);
    }
}
